/**
 * Copyright (c) 2018 开源 All rights reserved.
 * <p>
 * https://www.sxyc.io
 * <p>
 * 版权所有，侵权必究！
 */

package io.renren.controller;

import io.renren.common.utils.Result;
import io.renren.modules.yckj.dto.ProjectDTO;
import io.renren.modules.yckj.enums.status.CommonStatus;
import io.renren.modules.yckj.enums.type.HotType;
import io.renren.modules.yckj.service.MachineService;
import io.renren.modules.yckj.service.ProjectService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 测试接口
 *
 * @author Mark sunlightcs@gmail.com
 */
@RestController
@RequestMapping("/yckj/project")
@Tag(name = "项目接口")
@AllArgsConstructor
public class ApiProjectController {

    private final ProjectService projectService;

    @GetMapping("hot")
    @Operation(summary = "热门列表")
    @ApiResponse(content = @Content(mediaType = "application/json",
            schema = @Schema(implementation = ProjectDTO.class)))
    public Result<List<ProjectDTO>> hot() {
        Map<String, Object> map = new HashMap<>();
        map.put("recommend", HotType.YES.getCode());
        map.put("status", CommonStatus.YES.getCode());
        List<ProjectDTO> list = projectService.list(map);
        return new Result<List<ProjectDTO>>().ok(list);
    }

    @GetMapping("cate/list")
    @Operation(summary = "根据分类获取列表")
    @ApiResponse(content = @Content(mediaType = "application/json",
            schema = @Schema(implementation = ProjectDTO.class)))
    @Parameter(name = "cateId", description = "分类Id", required = true)
    public Result<List<ProjectDTO>> list(@RequestParam("cateId") Long cateId) {
        Map<String, Object> map = new HashMap<>();
        map.put("cateId", cateId);
        map.put("status", CommonStatus.YES.getCode());
        List<ProjectDTO> list = projectService.list(map);
        return new Result<List<ProjectDTO>>().ok(list);
    }


    @GetMapping("machine/list")
    @Operation(summary = "根据机器Id获取项目列表")
    @ApiResponse(content = @Content(mediaType = "application/json",
            schema = @Schema(implementation = ProjectDTO.class)))
    @Parameter(name = "machineId", description = "机器Id", required = true)
    public Result<List<ProjectDTO>> projectsByMachineId(@RequestParam("machineId") Long machineId) {
        Map<String, Object> map = new HashMap<>();
        map.put("machineId", machineId);
        List<ProjectDTO> list = projectService.getProjectListByMachineId(map);
        return new Result<List<ProjectDTO>>().ok(list);
    }

    @GetMapping("search")
    @Operation(summary = "搜索列表")
    @ApiResponse(content = @Content(mediaType = "application/json",
            schema = @Schema(implementation = ProjectDTO.class)))
    @Parameter(name = "name", description = "name", required = true)
    public Result<List<ProjectDTO>> search(@RequestParam("name") String name) {
        Map<String, Object> map = new HashMap<>();
        map.put("name", name);
        map.put("status", CommonStatus.YES.getCode());
        List<ProjectDTO> list = projectService.list(map);
        return new Result<List<ProjectDTO>>().ok(list);
    }
}